import componentData from './routerPath'
import iconData from './iconUtil'
export default function (data) {
  window.sessionStorage.setItem('user', JSON.stringify(data.userInfoVO))
  let routerData = [{
    path: '/index',
    name: 'index',
    component: 'index',
    children: [
      {
        path: '/index/home',
        name: 'home',
        component: 'Home'
      },
      {
        path: '/order/orderDetail',
        component: 'order/orderDetail'
      },
      {
        path: '/auditing/goodsAuditing/:id',
        component: 'auditing/goodsAuditing'
      },
      {
        path: '/goods/goodsAuditing',
        component: 'goods/goodsAuditing'
      }
    ],
    redirect: '/index/home'
  }]
  let routerTemp = []
  componentData.forEach(item => {
    routerTemp[item.path] = item
  })
  let temp = []
  data.sets.forEach(item => {
    item.children = []
    item.icon = iconData['icon' + item.setId]
    temp['P' + item.setId] = item
  })
  data.permissions && data.permissions.forEach(item => {
    if (routerTemp[item.uri]) {
      routerData[0].children.push(routerTemp[item.uri])
    }
    if (item.permissionSetId) {
      temp['P' + item.permissionSetId].children.push(item)
    }
  })

  // this.addDataToRouter(routerData)

  let menu = []
  for (let i in temp) {
    menu.push(temp[i])
  }
  window.sessionStorage.setItem('menu', JSON.stringify(menu))
  return routerData
}
